/*
 * FunctionRootsApp.java
 */
package functionroots.gui;

import functionroots.methods.Bissection;
import functionroots.methods.IntervalData;
import functionroots.primitives.RealFunction;
import functionroots.primitives.RootFinder;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;

/**
 * The main class of the application.
 */
public class FunctionRootsApp extends SingleFrameApplication {

    /**
     * At startup create and show the main frame of the application.
     */
    @Override
    protected void startup() {
        show(new FunctionRootsView(this));
    }

    /**
     * This method is to initialize the specified window by injecting resources.
     * Windows shown in our application come fully initialized from the GUI
     * builder, so this additional configuration is not needed.
     */
    @Override
    protected void configureWindow(java.awt.Window root) {
    }

    /**
     * A convenient static getter for the application instance.
     * @return the instance of FunctionRootsApp
     */
    public static FunctionRootsApp getApplication() {
        return Application.getInstance(FunctionRootsApp.class);
    }

    /**
     * Main method launching the application.
     */
    public static void main(String[] args) {
        // A linha abaixo oi automaticamente gerada pelo editor de código.
        // Descomente-a e comente as demais para obter a interface gárifca rodando.
        //launch(FunctionRootsApp.class, args);
        RootFinder probe = new Bissection(RealFunction.cossine, 0.0001);
        float a = 0, b = 2;
        double x;
        try {
            x = probe.scan(new IntervalData(a, b));
            System.out.println("Estimated root for cossine in interval [" + a
                    + ", " + b + "] is " + x);
            System.out.println(probe.getFunction().value(x));

            a = 3; b = 7;
            probe.setFunction(RealFunction.sine);
            x = probe.scan(new IntervalData(a, b));
            System.out.println("Estimated root for arcsine in interval [" + a
                    + ", " + b + "] is " + x);
            System.out.println(probe.getFunction().value(x));
        } catch (Exception ex) {
            System.out.println(ex.getMessage());
            Logger.getLogger(Bissection.class.getName()).log(Level.SEVERE,
                    null, ex);
        }
    }
}
